<?php
namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;


use App\Models\OrderModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Logics\OrderGroupLogic;
use App\Logics\OrderLogic;
use App\Logics\LogXxhfLogic;
use App\Logics\ChannelLogic;




use Illuminate\Support\Facades\Storage;
class OrderGroupController extends BaseController{

    private function getInstance(){
        static $ob=null;
        if($ob===null){
            $ob=new OrderGroupLogic();
        }
        return $ob;
    }
    //订单分组列表
    public function index()
    {
        $page = (int)request("page", 1);
        $per_page = (int)request("per_page", 20);
        $id=(int)request('id',0);
        $name =trim(request('name',''));

        $para=[
            'page'=>$page,
            'per_page'=>$per_page,
            'id'=>$id,
            'name'=>$name
        ];

        $ob= $this->getInstance();
        $arr= $ob->getOrderGroupList($para);
        if($arr && is_string($arr)) die(json_error($arr));

        $content= view("admin.order.orderGroup",$arr) ;
        $data=[
            'content'=>$content,
            'header'=>'订单分组列表',
        ];
        return  $this->baseList($data);
    }

    public function edit(){
        if($_POST){
            $id=(int)request('id');
            $name=trim(request('name'));
            $desc=trim(request('desc'));

            $para=[
                'id'=>$id,
                'name'=>$name,
                'desc'=>$desc
            ];
            $ob=$this->getInstance();
            $data=$ob->edit($para);
            $this->result($data);
        }
    }

    public function add(){
        if($_POST){
            $name=trim(request('name'));
            $desc=trim(request('desc'));
            $para=[
                'name'=>$name,
                'desc'=>$desc
            ];

            $ob=$this->getInstance();
            $data=$ob->add($para);
            $this->result($data);
        }
    }


    /**
     * 删除
     */
    public function delete(){
        if($_POST){
            $id=(int)request('id');
            if($id<1) die(json_error('参数有误'));
            $ob=$this->getInstance();
            $data=$ob->delete($id);
            $this->result($data);
        }
    }

    /**
     * 分组订单列表
     * @return string
     */
    public function groupOrderList(){
        $page = (int)request("page", 1);
        $per_page = (int)request("per_page", 20);
        $order_status=(int)request('order_status',-1);

        $order_type=(int)request('order_type');
        $order_comefrom =trim(request('order_comefrom'));
        $order_id=trim(request('order_id'));
        $goods_name=trim(request('goods_name'));
        $user_phone=trim(request('user_phone'));
        $user_name=trim(request('user_name'));
        $start_time=trim(request('start_time',''));
        $end_time=trim(request('end_time',''));
        $group_id=(int)request('group_id','');

        $para=[
            'page'=>$page,
            'per_page'=>$per_page,
            'order_status'=>$order_status,
            'order_type'=>$order_type,
            'order_comefrom'=>$order_comefrom,
            'order_id'=>$order_id,
            'goods_name'=>$goods_name,
            'user_phone'=>$user_phone,
            'start_time'=>$start_time,
            'end_time'=>$end_time,
            'group_id'=>$group_id,
        ];

         $ob=$this->getInstance();
         $arr=$ob->groupOrderList($para);
         if($arr && is_string($arr)) die(json_error($arr));

//        p($arr);die;
        $content= view("admin.order.index",$arr) ;
        $data=[
            'content'=>$content,
            'header'=>'订单列表',
        ];
        return  $this->frameList($data);
    }







}